$("#login").click(function(){
    var url=window.location.href;
    setCookie("backUrl",url,7);
    window.location.href="html/login.html";
})
$("#join").click(function(){
    var url=window.location.href;
    setCookie("backUrl",url,7);
    window.location.href="html/join.html";
})
//轮播图
var timer=null;
var index=0;
start();    
function showBn(){
    $(".bnNav li").each(function(i,n){
        $(n).removeClass("bnSelected");
        $(".bnContent li").eq(i).removeClass("bnSelected");
    })
    $(".bnNav li").eq(index).addClass("bnSelected");
    $(".bnContent li").eq(index).addClass("bnSelected")
    
}
$(".bnNav li").each(function(i,n){ 
    $(n).mousemove(function(){
        index=i; 
        clearInterval(timer);
        showBn();    
   })
   $(n).mouseout(function(){
       start();
   })   
})

$(".bnContent").click(function(){
    window.location.href="html/fenye.html";
})
function start(){
     timer=setInterval(function(){
        index++
        if(index==$(".bnNav li").length){
            index=0;
        }          
        showBn();    
    },2000)
}
//进入详情页
$(".cngift li").each(function(i,n){
    $(n).click(function(){
        window.location.href="html/fenye.html"
    })
})
$(".newUlLi1").eq(0).click(function(){
    window.location.href="html/fenye.html"
})
//new
newInfo(1,".newUlLi1");
newInfo(2,".cnBirthday2");
newInfo(3,".cnDesign2");

function newInfo(neibie,obj){
    $.ajax({
        type: "get",
        url: "php/newinfo.php",
        data: {"neibie":neibie},
        dataType: "json",
        success: function (list) {
            var html="";
            $(list).each(function(i,n){
                var id=n.id;
                var smallimg=n.smallimg;
                var goodsname=n.goodsname;
                var price=n.price;
                html+= `
                <li class="goodsLi" data-id='${id}' onclick="shoppingcar(${id})">
                    <img src="images/${smallimg}" alt="">
                    <p>${goodsname}</p>
                    <div><span class="iconfont icon-qian">${price}</span></div>
                </li>
                `
            })
            if(neibie==1){
                $(obj).after(html);
            }else{
                $(obj).append(html);
            }
            
        }
    });
}
$(".cnBirthday1").click(function(){
    var id=$(this).attr("data-id");
    shoppingcar(id)
})
$(".cnDesign1").click(function(){
    var id=$(this).attr("data-id");
    shoppingcar(id)
})
//购物车详情页面
function shoppingcar(id){
    window.location.href="html/shoppingcar.html?id="+id;
}
//模糊查询
$(".icon-sousuo").click(function(){
    var neirong=$(".headerp1").val();
    window.location.href="html/search.html?neirong="+neirong;
   
})
//购物车计数
var usertel=getCookie("logintel");
if(usertel){
    $.ajax({
        type: "get",
        url: "php/num.php",
        data: {"usertel":usertel},
        dataType: "json",
        success: function (item) {
            if(item[0]>0){
                $("#shoppingcar").html(item[0]);
                $("#shoppingcar").css("display","block");
            }
           
        }
    });
}
//返回顶部
$(".icon-fanhuidingbu").click(function () { 
    $("html, body").animate({scrollTop: 0}, 1500); /* 持续时间为 100ms */
    return false;
});
//顶部导航点击跳转
$.each($('.headerUlLi2').nextAll(),function(i,n){
    $(n).click(function(){
        window.location.href="html/fenye.html"
    })
})
//header fixed定位
$(document).scroll(function(){
    if($(document).scrollTop()>=100){
        $(".wheader").css({"position":"fixed","top":0,"left":0,"right":0,"background":"white","width":"100%"})
       
    }else{
        $(".wheader").css("position","static");
    }
});
//点击购物车图片跳转购物车
$(".icon-tubiaolunkuo-").click(function(){
    window.location.href="html/shopping.html";
})
//登录以后小人里面放用户电话号码
$(".icon-gerenxinxi").hover(
    function(){
        if(getCookie("logintel")){
            $(".xinxiboxLi").html(getCookie("logintel"))
        }
    }
)
